package com.rick.awarenessdemo

import android.content.BroadcastReceiver
import android.content.Context
import android.content.Intent
import com.amap.api.services.core.PoiItem
import com.blankj.utilcode.util.GsonUtils
import com.huawei.hms.kit.awareness.barrier.BarrierStatus
import com.rick.awarenessdemo.util.LogUtil

/**
 * 地理围栏广播接收者
 */
class LocationBarrierReceiver : BroadcastReceiver() {
    override fun onReceive(context: Context, intent: Intent) {
        val barrierStatus = BarrierStatus.extract(intent)
        LogUtil.log("LocationBarrierReceiver onReceive ${GsonUtils.toJson(barrierStatus)}")
        if (barrierStatus.presentStatus == BarrierStatus.TRUE) {
            MainActivity.start(
                context,
                GsonUtils.fromJson(barrierStatus.barrierLabel, PoiItem::class.java)
            )
        }
    }
}